/*
 * @Author: your name
 * @Date: 2021-01-15 10:21:51
 * @LastEditTime: 2021-01-21 09:57:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \myReposCode\time\ymdhms.cpp
 */

#include <iostream>
// #include <string>
#include <cstdio>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <thread>
#include <chrono>

using namespace std;

// 年-月-日 时-分-秒 ;
char *getCurrentTimeStr()
{
	time_t t = time(NULL);
	static char ch[64] = {0};
	strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S\n", localtime(&t));
	return ch;
}

int testarg(char *p, int i, ...)
{
	va_list sArgv;
	va_start(sArgv, i);
	va_arg(sArgv, double);
	va_arg(sArgv, int);
	va_end(sArgv);
	return 0;
}

int main()
{
	// cout << getCurrentTimeStr() << endl;
	printf("%s", getCurrentTimeStr());
	double a = -2;
	double b = abs(a);
	cout << "b = " << b << endl;

	char buffer[L_tmpnam];
	char *ptr;

	tmpnam(buffer);
	printf("临时名称 1: %s\n", buffer);

	ptr = tmpnam(NULL);
	printf("临时名称 2: %s\n", ptr);
	cout << "strlen(ptr) = " << strlen(ptr) << endl;
	cout << "sizeof(ptr) = " << sizeof(ptr) << endl;

	char *str;

	/* 最初的内存分配 */
	str = (char *)malloc(15);
	strcpy(str, "runoob");
	printf("String = %s,  Address = %p\n", str, str);

	/* 重新分配内存 */
	str = (char *)realloc(str, 2);
	strcat(str, ".com");
	printf("String = %s,  Address = %p\n", str, str);

	free(str);

	char command[50];

	strcpy(command, "dir");
	system(command);

	int i, n;
	time_t t;

	n = 5;

	/* 初始化随机数发生器 */
	srand((unsigned int)time(&t));

	/* 输出 0 到 50 之间的 5 个随机数 */
	for (i = 0; i < n; i++)
	{
		printf("%d\n", rand() % 50);
	}

	time_t rawtime;
	struct tm *info;
	struct tm *info1;

	time(&rawtime);

	info = localtime(&rawtime);
	printf("当前的本地时间和日期：%s", asctime(info));
	std::this_thread::sleep_for(std::chrono::seconds(2));
	time(&rawtime);
	localtime(&rawtime);
	printf("当前的本地时间和日期：%s", asctime(info));
	// printf("当前的本地时间和日期：%s", asctime(info1));
	char c = 1;

	cout << int(c) << endl;

	return 0;
}
